﻿// 定义粒子类的类型
export class ParticleLimit {
    x: number;
    y: number;
    directionX: number;
    directionY: number;
    size: number;
    color: string;
    
    constructor(
        x: number,
        y: number,
        directionX: number,
        directionY: number,
        size: number,
        color: string
    ) {
        this.x = x;
        this.y = y;
        this.directionX = directionX;
        this.directionY = directionY;
        this.size = size;
        this.color = color;
    }
    
    // 绘制粒子
    draw(ctx: CanvasRenderingContext2D): void {
        ctx.beginPath();
        ctx.arc(this.x, this.y, this.size, 0, Math.PI * 2, false);
        ctx.fillStyle = this.color;
        ctx.fill();
    }
    
    // 更新粒子位置
    update(canvas: HTMLCanvasElement, ctx: CanvasRenderingContext2D): void {
        // 边界检测
        if (this.x + this.size > canvas.width || this.x - this.size < 0) {
            this.directionX = -this.directionX;
        }
        if (this.y + this.size > canvas.height || this.y - this.size < 0) {
            this.directionY = -this.directionY;
        }
        
        // 移动粒子
        this.x += this.directionX;
        this.y += this.directionY;
        
        // 重新绘制
        this.draw(ctx);
    }
}